package com.cskaoyan.exceptionhandler;

import com.cskaoyan.vo.BaseRespVo;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 作者：grz
 * 功能：捕获数据库异常，进行处理
 * 唯一字段重复、主键冲突等
 */
@ControllerAdvice
public class SQLExceptionHandler {

    @ExceptionHandler(value =DuplicateKeyException.class)
    @ResponseBody
    public BaseRespVo duplicateKeyExceptionHandler(Exception e){
        return BaseRespVo.error("唯一属性的参数重复");
    }
}
